package com.bouncy.ball;

import android.content.Context;
import android.gesture.GestureOverlayView;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class ViewFinder extends View implements OnGestureListener {
	private ColorBall ball1;
	private Paint p;
	private GestureDetector detect;

	public ViewFinder(Context context) {
		super(context);
		//this.setOnTouchListener(this);
		
		setFocusable(true);
		ball1 = new ColorBall(50,50,5,5,Color.BLUE, context);
		setFocusableInTouchMode(true);
		
		detect = new GestureDetector(this);
	}
	@Override
	public boolean onTouchEvent(MotionEvent m){
		return detect.onTouchEvent(m);
		
	}
	
	@Override
	public void onDraw(Canvas c){
		//ball1.move(5, 5, ball1);
		ball1.update();
		p = new Paint();

		p.setAntiAlias(true);
		

		c.drawCircle(ball1.getX(), ball1.getY(), 25, p);
		invalidate();
	}


	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		ball1.setColor(Color.RED);
		if(e1.getX() >= ball1.getX() -30 && e1.getX() <= ball1.getX() + 20){
			ball1.setVelocityX(-10);
			
		}
		if(e1.getY() >= ball1.getY() - 30 && e1.getY() <= ball1.getY() + 20){
			ball1.setVelocity(-10);
		
		}
		
		return true;
	}
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}


}
